function [ExoFixedStates,MidPointsFixedStates] = GenExoFixedStates(DS,opt) 

% Distance variables is the first one:
if opt.fakedata % If data is fake change variables names before loading
    opt.TransCostVar = {'TransCostVar'}; opt.PotenYield = {'PotenYield'}; opt.CostVar = {'CostVar'};
end


ExoFixedBig = double(DS(:,[opt.TransCostVar, opt.PotenYield, opt.CostVar]));

% rescale DistanceVar:
ExoFixedBig(:,1) = ExoFixedBig(:,1)*opt.TransCostVarRS;
% rescale yield:
ExoFixedBig(:,2) = ExoFixedBig(:,2)*opt.PotenYieldRS;

% Normalize cost related variables:
if opt.UseNormalizedReg
    %mean  = kron(nanmean(ExoFixedBig(:,3:end)),ones(size(DS,1),1));
    std   = kron(nanstd(ExoFixedBig(:,3:end)),ones(size(DS,1),1));
    ExoFixedBig(:,3:end) = (ExoFixedBig(:,3:end))./std;
end

Q = linspace(0,1,opt.NumFixedStates+1);

Thresholds = quantile(ExoFixedBig,Q);

[ExoFixedStates,MidPointsFixedStates] = ClassStates(ExoFixedBig,Thresholds);

% Classify data in other land use categories: 
% OtherLandShares = double(DS(:,{opt.ShareCropland, opt.SharePasture}));
% OtherLandShares = [OtherLandShares, 1 - sum(OtherLandShares,2)];
% 
% [LUState] = LandUseClass(OtherLandShares);
% ExoFixedStates = [ExoFixedStates LUState]; % Last state is land use class.
% LUState = 1 Other use
% LUState = 2 Pasture
% LUState = 3 Cropland

LUState = ones(size(DS,1),1);
LUState(DS.mb_uso_detalhe == 15) = 2; % Pasture (MapBiomas classification)
LUState(DS.mb_uso_detalhe >= 18 & DS.mb_uso_detalhe <= 21) = 3; % Agriculture (MapBiomas classification)

ExoFixedStates = [ExoFixedStates LUState]; % Last state is land use class.

end



